//
//  Account.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/20.
//

#import "Account.h"
@interface Account()
@property (nonatomic,strong)UIButton *agree;
@end
@implementation Account

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setupUI
{
    UIView *view = [UIView new];
    [self addSubview:view];
    view.backgroundColor = UIColor.clearColor;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(0);
        make.left.mas_offset(17);
        make.right.mas_offset(-17);
        make.height.mas_equalTo(420);
    }];
    UIImageView *bgIV = [[UIImageView alloc] initWithFrame:self.bounds];
    bgIV.image = [UIImage imageNamed:@"bankbg"];
    [view addSubview:bgIV];
    [view sendSubviewToBack:bgIV];
    [bgIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.bottom.mas_offset(-50);
    }];

    UILabel *lab = [UILabel new];
    lab.textColor = HexColor(@"#000000");
    lab.font = [UIFont systemFontOfSize:28 weight:UIFontWeightBold];
    lab.text = @"Account cancellation";
    [view addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(24);
        make.centerX.mas_equalTo(view);
    }];
    UILabel *detail = [UILabel new];
    detail.numberOfLines = 0;
    detail.text = @"The account cannot be restored after cancellation. To ensure the security of your account please confirm that the services related to the account have beenproperly handled before application and pay attention to the following provisions:  ";
    detail.textColor = HexColor(@"#000000");
    detail.textAlignment = NSTextAlignmentCenter;
    detail.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
    [view addSubview:detail];
    [detail mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab.mas_bottom).offset(22);
        make.left.mas_offset(28);
        make.right.mas_offset(-28);
    }];
    
    UILabel *yello = [UILabel new];
    yello.text = @"All loans have been repaid";
    yello.textColor = HexColor(@"#FF9E01");
    yello.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    [view addSubview:yello];
    [yello mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(detail.mas_bottom).offset(16);
        make.left.mas_offset(28);
        make.right.mas_offset(-28);
    }];
    
    UIButton *agree = [UIButton buttonWithType:UIButtonTypeCustom];
    [agree setImage:[UIImage imageNamed:@"no"] forState:UIControlStateNormal];
    [agree setImage:[UIImage imageNamed:@"yes"] forState:UIControlStateSelected];
    [view addSubview:agree];
    [agree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(yello.mas_bottom).offset(14);
        make.left.mas_offset(28);
    }];
    UILabel *ag = [UILabel new];
    ag.text =@"I have read and agreed to the above";
    ag.textColor = HexColor(@"#0F0F0F");
    ag.font = [UIFont systemFontOfSize:14];
    [view addSubview:ag];
    [ag mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(agree.mas_right).offset(8);
        make.centerY.mas_equalTo(agree);
    }];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setBackgroundImage:[UIImage imageNamed:@"logout"] forState:UIControlStateNormal];
    [btn setTitle:@"Cancel" forState:UIControlStateNormal];
    [btn setBackgroundColor:HexColor(@"#2C64FF")];
    btn.layer.cornerRadius = 25;
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightBold];
    [view addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(agree.mas_bottom).offset(20);
        make.left.mas_offset(16);
        make.right.mas_offset(-16);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *close = [UIButton buttonWithType:UIButtonTypeCustom];
    [close setTitle:@"Canceling account >" forState:UIControlStateNormal];
    [close setTitleColor:HexColor(@"#D7D7D7") forState:UIControlStateNormal];
    close.titleLabel.font = [UIFont systemFontOfSize:16];

    [self addSubview:close];
    [close mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self);
        make.bottom.mas_offset(-20);
    }];
    [close addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
    [btn addTarget:self action:@selector(apply) forControlEvents:UIControlEventTouchUpInside];
    [agree addTarget:self action:@selector(agree:) forControlEvents:UIControlEventTouchUpInside];
    _agree = agree;
}
-(void)agree:(UIButton*)sender
{
    sender.selected = !sender.selected;
}
-(void)close
{
    if (_agree.selected) {
            if (self.closeAction) {
                self.closeAction();
            }
        }else{
            if (self.toastAction) {
                self.toastAction();
            }
        }
}
    
-(void)apply
{
    if(self.commitAction) {
        self.commitAction();
    }
}

@end
